package uk.ac.manchester.tewpl.iceiface.client.service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import uk.ac.manchester.tewpl.iceiface.client.ExploriumClientException;
import uk.ac.manchester.tewpl.iceiface.client.model.KBClassModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBCommunityModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBDatatypePropertyModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBDatatypePropertyValueModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBIndividualModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBInfoModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBObjectPropertyModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBObjectPropertyValueModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBResourceModel;
import uk.ac.manchester.tewpl.iceiface.client.model.KBWorkspaceModel;
import uk.ac.manchester.tewpl.iceiface.client.tree.Tree;

import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("kbservice.rpc")
public interface KBService extends RemoteService {

	/**
	 * Finds all knowledge bases for a given community
	 * 
	 * @param community
	 * @return
	 * @throws ExploriumClientException
	 */
	Collection<KBWorkspaceModel> findWorkspacesByCommunity(
			KBCommunityModel community) throws ExploriumClientException;

	/**
	 * Creates a Knowledge Base
	 * 
	 * @param uri
	 * @param name
	 * @param description
	 * @return
	 * @throws KnowledgeBaseException
	 */
	KBInfoModel createKnowledgeBase(String uri, String name,
			String description) throws ExploriumClientException;

	KBInfoModel saveKBInfo(KBInfoModel kb) throws ExploriumClientException;;

	void deleteKnowledgeBaseByUri(String uri) throws ExploriumClientException;;

	KBClassModel saveClass(KBClassModel cls) throws ExploriumClientException;;

	Tree<KBClassModel> findClassHierarchy(KBWorkspaceModel ws)
			throws ExploriumClientException;

	void deleteClass(KBClassModel cls) throws ExploriumClientException;

	Collection<KBIndividualModel> findIndividuals(KBClassModel cls, KBWorkspaceModel ws)
			throws ExploriumClientException;
	
	Collection<KBIndividualModel> findIndividualsWithFilter(String filter, KBClassModel cls,
			KBWorkspaceModel ws) throws ExploriumClientException;

	PagingLoadResult<KBIndividualModel> findIndividualsPaged(PagingLoadConfig config,
			KBClassModel cls, KBWorkspaceModel ws)
			throws ExploriumClientException;

	void deleteIndividual(String workspaceUri, KBIndividualModel individual)
			throws ExploriumClientException;

	KBIndividualModel saveIndividual(String workspaceUri, KBIndividualModel individual)
			throws ExploriumClientException;

	BasePagingLoadResult<KBInfoModel> findAllKnowledgeBases();

	Collection<KBDatatypePropertyModel> findDatatypePropertiesForIndividual(
			String workspaceUri, KBIndividualModel individual) throws ExploriumClientException;

	Collection<KBDatatypePropertyValueModel> findAllDataPropertyValues(
			String workspaceUri, KBIndividualModel individual) throws ExploriumClientException;

	Collection<KBObjectPropertyValueModel> findAllObjectPropertyValues(
			String workspaceUri, KBIndividualModel individual) throws ExploriumClientException;

	Collection<KBObjectPropertyModel> findObjectPropertiesForIndividual(
			String workspaceUri, KBIndividualModel individual) throws ExploriumClientException;
	
	void purgeCachedKnowledgeBase(KBInfoModel kb);
	
	Collection<KBClassModel> findSubClasses(KBClassModel cls, KBWorkspaceModel ws) throws ExploriumClientException;
	
	Collection<KBClassModel> findSuperClasses(KBClassModel cls, KBWorkspaceModel ws) throws ExploriumClientException;
	
	KBDatatypePropertyValueModel saveDatatypePropertyValue(String workspaceUri, KBDatatypePropertyValueModel kdpv, KBDatatypePropertyModel kdp, KBIndividualModel ind) throws ExploriumClientException;
	
	KBObjectPropertyValueModel saveObjectPropertyValue(String workspaceUri, KBIndividualModel value, KBObjectPropertyModel property, KBIndividualModel ind) throws ExploriumClientException;
	
	Collection<KBDatatypePropertyModel> findDatatypePropertiesForClass(KBClassModel cls) throws ExploriumClientException;
	
	Collection<KBObjectPropertyModel> findObjectPropertiesForClass(KBClassModel cls) throws ExploriumClientException;
	
	Collection<KBClassModel> findClassesFromCSV(String kbURI, String ws, String csv) throws ExploriumClientException;
	
	Collection<KBIndividualModel> findRelatedIndividualsOfClass(String workspaceUri, KBIndividualModel ind, KBClassModel cls) throws ExploriumClientException;
	
	Collection<KBClassModel> findRootClasses(KBWorkspaceModel ws) throws ExploriumClientException;
	
	KBClassModel findClass(String classUri, KBWorkspaceModel ws) throws ExploriumClientException;
	
	Collection<Map<String, KBIndividualModel>> executeQuery(String query, KBWorkspaceModel ws) throws ExploriumClientException;
	
	Map<KBObjectPropertyModel, Collection<KBIndividualModel>> findIndividualObjectPropertyValues(String individualUri, KBWorkspaceModel ws) throws ExploriumClientException;
	
	KBIndividualModel findIndividual(String individualUri, KBWorkspaceModel ws) throws ExploriumClientException;

}
